package com.wanmait.wisdom.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.wisdom.entity.Rapair;
import com.wanmait.wisdom.mapper.RapairMapper;
import com.wanmait.wisdom.web.service.WebRapairService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class WebRapairServiceImpl extends ServiceImpl<RapairMapper, Rapair> implements WebRapairService {

    @Resource
    private RapairMapper repairMapper;

    //添加保修
    @Override
    public void insertRapair(Rapair repair) {
        repairMapper.insertSelective(repair);
    }

    @Override
    public PageInfo<Rapair> selectAllRapair(Rapair rapair, Date startTime, Date endTime,Integer pageNum, Integer pageSize) {
        LambdaQueryWrapper<Rapair> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Rapair::getResidentId,rapair.getResidentId());
        queryWrapper.ge(startTime!=null,Rapair::getTime,startTime);
        queryWrapper.le(endTime!=null,Rapair::getTime,endTime);
        queryWrapper.orderByDesc(Rapair::getTime);
        PageHelper.startPage(pageNum,pageSize);
        List<Rapair> list = repairMapper.selectList(queryWrapper);
        PageInfo<Rapair> pageInfo = new PageInfo<>(list,11);
        return pageInfo;
    }

    @Override
    public Rapair selectById(Integer id) {
        LambdaQueryWrapper<Rapair> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Rapair::getId,id);
        return repairMapper.selectOne(queryWrapper);
    }

    @Override
    public void deleteById(Integer id) {
        repairMapper.deleteById(id);
    }
}
